package com.hands.sample.service.impl;

import com.hands.commen.entity.wx.HostInfo;
import com.hands.sample.mapper.HostInfoMapper;
import com.hands.sample.service.HostInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class HostInfoServiceImpl implements HostInfoService {

    @Autowired
    private HostInfoMapper hostInfoMapper;

    @Override
    @Transactional
    public int insertInfo(HostInfo hostInfo) {
        List<HostInfo> hostInfos = hostInfoMapper.selectHostInfoExcMac(hostInfo);
        int i=0;
        //更新
        if(hostInfos.size()>0){
            HostInfo host = hostInfos.get(0);
            host.setDevMac(hostInfo.getDevMac());
            i=hostInfoMapper.updateInfo(host);

        }else{
            //插入
             i= hostInfoMapper.insertInfo(hostInfo);
        }
        return i;
    }

    @Override
    public List<HostInfo> selectHostInfoList(HostInfo hostInfo) {
        return hostInfoMapper.selectHostInfoList(hostInfo);
    }

    @Override
    @Transactional
    public int updateInfo(HostInfo hostInfo) {
        return hostInfoMapper.updateInfo(hostInfo);
    }
}
